﻿using System;
using System.Web;
using System.Data;
using System.Text;
using VIT.DataHelper;
using System.Data.SqlClient;
using System.Reflection;
using System.Collections.Generic;

namespace VIT.Web.Modules.StaticPage
{
    public class StaticPageProvider : VIT.DataHelper.DataAccess.SQLSupport
    {
        #region Properties
        public string Id { get; set; }
        public string LanguageId { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string Contents { get; set; }
        public string Tag { get; set; }
        #endregion

        #region Constructor
        public StaticPageProvider(string id = "",
                        string languageId = "",
                        string image = "",
                        string title = "", 
                        string description = "",                        
                        string contents = "",
                        string tag = "")
        {
            this.Id = id;            
            this.LanguageId = languageId;         
            this.Title = title;
            this.Description = description;            
            this.Contents = contents;
            this.Tag = tag;
        }
        #endregion

        #region Pre
        public void GetSingle(Dictionary<string, string> param)
        {
            string Id;
            try { Id = param["Id"]; }
            catch { Id = string.Empty; }

            string strQuery = "select Id, Title, Description, Contents, Tag from Page where LanguageId=@LanguageId and Id=@Id";
            SqlParameter IdP = new SqlParameter("@Id", Id);
            SqlParameter LanguageId = new SqlParameter("@LanguageId", this.LanguageId);
            DataTable dt = ExecuteDataset(false, strQuery, IdP, LanguageId).Tables[0];

            if (dt.Rows.Count > 0)
            {
                this.Title = dt.Rows[0]["Title"].ToString();
                this.Description = dt.Rows[0]["Description"].ToString();
                this.Contents = dt.Rows[0]["Contents"].ToString();
                this.Tag = dt.Rows[0]["Tag"].ToString();
            }
            else this.Id = "";
        }  
        #endregion
    }
}
